/**
 * Copyright (C) 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gjc.client.example;

import org.gjc.client.dispatcher.DefaultDispatchAsync;
import org.gjc.client.example.dto.ExampleDto;

import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 *
 *
 * @author <a href="mailto:mail@raphaelbauer.com">rEyez</<a>
 *
 */
public class ApiCommandPatternTestGwt extends GWTTestCase {

    public static final String SERVLET_DELETE_RESPONSE = "delete";
    public static final String SERVLET_GET_RESPONSE = "get";
    public static final String SERVLET_POST_RESPONSE = "post";
    // W3C's XMLHttpRequest requires it be the empty string
    public static final String SERVLET_HEAD_RESPONSE = "";
    public static final String SERVLET_PUT_RESPONSE = "put";

    public static final String exampleResponse
        = "{\"name\":\"myName\"}";
    @Override
    public String getModuleName() {
        return "org.gjc.ApiCommandPatternTestGwt";
    }

    public void testGetExampleAction() {

        GetExampleAction getExampleAction = new GetExampleAction();

        DefaultDispatchAsync defaultDispatchAsync = new DefaultDispatchAsync(
                GWT.getModuleBaseURL() + "api/");

        defaultDispatchAsync.execute(getExampleAction,
                new AsyncCallback<ExampleDto>() {

                    @Override
                    public void onFailure(Throwable caught) {
                    	fail();
                        finishTest();
                    }

                    @Override
                    public void onSuccess(ExampleDto result) {

                        assertEquals("myName", result.getName());
                        finishTest();

                    }
                });

        delayTestFinish(500);

    }

}